#include <vector>
#include <iostream>
using namespace std;

int cal(vector<vector<int>> &digit)
{
	int n = digit.size() - 2;

	for (int i = n; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			digit[i][j] = max(digit[i + 1][j], digit[i + 1][j + 1]) + digit[i][j];
		}
	}

	return digit[0][0];
}

int recursion(int i, int j, vector<vector<int>>& digit, vector<vector<int>> &rec)
{
	if(rec[i][j]){
		return rec[i][j];
	}
	if (i == digit.size() - 1) {
		return rec[i][j] = digit[i][j];
	}

	int left = recursion(i + 1, j, digit, rec);
	int right = recursion(i + 1, j + 1, digit, rec);

	return rec[i][j] = max(left, right) + digit[i][j];
}

int main()
{
	int n = 0;
	cin >> n;
	vector<vector<int>> digit(n, vector<int>(n, 0)), rec(digit);

	for(int i = 0; i < n; i++){
		for(int j = 0; j <=i; j++){
			cin >> digit[i][j];
		}
	}

	cout<<recursion(0, 0, digit, rec)<<endl;
	return 0;
}
